/**
 * 游戏时间管理类
 */
export class Time {
    private startTime: number = 0;
    private currentTime: number = 0;
    private deltaTime: number = 0;
    private timeScale: number = 1;
    private isRunning: boolean = false;
    
    /**
     * 获取游戏运行时间（秒）
     */
    public get time(): number {
        return this.currentTime;
    }
    
    /**
     * 获取帧间隔时间（秒）
     */
    public get delta(): number {
        return this.deltaTime * this.timeScale;
    }
    
    /**
     * 获取时间缩放
     */
    public get scale(): number {
        return this.timeScale;
    }
    
    /**
     * 设置时间缩放
     */
    public set scale(value: number) {
        this.timeScale = Math.max(0, value);
    }
    
    /**
     * 获取游戏是否正在运行
     */
    public get running(): boolean {
        return this.isRunning;
    }
    
    /**
     * 启动时间系统
     */
    public start(): void {
        if (this.isRunning) {
            return;
        }
        
        this.isRunning = true;
        this.startTime = performance.now() / 1000;
        this.currentTime = 0;
        this.deltaTime = 0;
    }
    
    /**
     * 停止时间系统
     */
    public stop(): void {
        this.isRunning = false;
    }
    
    /**
     * 更新时间
     */
    public update(deltaTime: number): void {
        if (!this.isRunning) {
            return;
        }
        
        this.deltaTime = deltaTime;
        this.currentTime = (performance.now() / 1000) - this.startTime;
    }
    
    /**
     * 重置时间系统
     */
    public reset(): void {
        this.startTime = performance.now() / 1000;
        this.currentTime = 0;
        this.deltaTime = 0;
    }
} 